
/**
 * Represents an adjacency matrix of a graph
 */
public class AdjacencyMatrix extends Matrix	//extending inherits the standard matrix data structure and print method
{
        private int _count;
        Boolean debug = main.debug;
        
        /**
         * Constructs a zero matrix of a certain size
         * @param s the size of the matrix
         */
        public AdjacencyMatrix(int s)
        {
        	super(s);	//calls parent constructor
        }

        /**
         * Reflects, in the adjacency matrix, an addition of an edge between vertex i and vertex j to the graph
         * NOTICE if adding an edge from a vertex i to itself this will 2 to element (i,i)
         * @param i the index of the vertex at the first end of the edge
         * @param j the index of the vertex at the second end of the edge 
         */
        public void add(int i, int j)
        {
                element[i][j] = 1;   // -1 to offset for array. (Please elaborate. Code makes sense, not sure on comment lol -Mark)
                element[j][i] = 1;
                _count++;
        }
        
        /**
         * uses the complete adjacency matrix to return an array where 
         * each index refers to a node and it's value is the nodes degree
         * @return an array of the degrees of vertices, as specified
         */
        public int[] getDegArray()
        {
        	int degrees[] = new int[this._size];
        	
                 //For each vertex degree degrees[p]
        	for(int p = 0; p < this._size; p++)
                {
                        //Add edges connecting to all vertices
        		for(int q = 0; q < this._size; q++)
        			degrees[p]+= element[p][q]; 
                }
                
        	return degrees;
        }
}
